<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no" />
    <link rel="stylesheet" type="text/css" href="../css/shenbaotijiao.css" />
    <title>填写资料</title>
</head>
<body>
    <div id="detail">
        <!-- <div class="act"><b>活动主题</b>：活动里程5折抢购</div>
        <div class="act"><b>活动时间</b>：2017年8月1日-2017年9月25日</div> -->
    </div>
    <!-- 活动标题时间模板 begin -->
    <script type="text/html" id="detail-template">
        <div class="act"><b>活动主题</b>：{{title}}</div>
        <div class="act"><b>活动时间</b>：{{time_start.split(' ')[0]}} 至 {{time_end.split(' ')[0]}}</div>
    
    <!-- 活动标题时间模板 end -->
    <div class="content">
        <div class="basic"><span class="color">*</span><b>基本资料填写</b></div>

        
        <div class="frame">
            <span class="name">姓名：</span>
            <div class="input">
                <input type="text" id="name" placeholder="请填写姓名">
            </div>
        </div>  
        <div class="frame">
            <span class="name">联系电话：</span>
            <div class="input">
                <input type="tel" placeholder="+86" id="tel">
            </div>
        </div> 
        <div class="frame">
            <span class="name">单位名称：</span>
            <div class="input">
                <select class="inner" id="unit_id">
                    <option value="">请选择</option>
                    {{each unit_id}}
                    <option value="{{$value.id}}"  {{if $value.id==cid}} selected {{/if}}>{{$value.title}}</option>
                    {{/each}}
                </select>
            </div>
        </div> 
        <div class="frame">
            <span class="name">单位部门：</span>
            <div class="input">
                <input type="text" id="department" placeholder="请填写单位部门">
            </div>
        </div>
        <div class="frame">
            <span class="name">工牌号：</span>
            <div class="input">
                <input type="text" id="unit_number" placeholder="请填写工牌号">
            </div>
        </div>
        <div class="submit"  onclick="fnSubmit()">提交资料</div> 
    </div>
    </script>
</body>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="../framework/template-web.js"></script>
<script type="text/javascript" src="../framework/zepto.min.js"></script>
<script type="text/javascript" src="../script/base.js"></script>
<script type="text/javascript">
    var param =  fnGetUrlParam();

    fnDetails();
    function fnDetails(){
        //公司名称列表
        fnAjax({
            url: "Company/aList",
            data: {
                type:1
            },
        }, function(ret){
            if( !ret.status ){
                var _unit_ids = ret.data.list;
                //活动详情
                fnAjax({
                    url: "Queandans/detail",
                    data: {
                        id:fnGetUrlParam().id
                    },
                }, function(ret){
                    if( !ret.status ){
                        ret.data.unit_id = _unit_ids;
                        if(ret.data){
                            fnGetUserInfo(ret.data);
                        }
                    }else{
                        
                    }
                });
            }else{
                
            }
        });
    }

    function fnGetUserInfo(_el){
        fnAjax({
            url: "Queandans/getUserInfo",
            data: {
                active_id:fnGetUrlParam().id
            },
        }, function(ret){
            if( !ret.status ){
                    _el.userinfo = ret.data;
                    fnStatus(_el);
            }else{
                
            }
        });
    }

    //查询用户状态
    function fnStatus(_el){
        console.log(_el);
        // fnAjax({
        //     url: "Declare/examineDetail",
        //     data: {
        //         id:fnGetUrlParam().id
        //     },
        // }, function(ret){
        //     if( !ret.status ){
        //         _el.cid = ret.data.unit_id;
        //         imgUrl = ret.data.pictrue;
                fnValue('#detail',template('detail-template', _el));
     //            if(ret.data.examine_type=='1'){
     //                fnValue('.submit','审核中');
     //                $('.submit').addClass('no-onclick');
     //            }else if(ret.data.examine_type=='2'){
     //                fnValue('.submit','重新提交申报');
					// $('#reason').removeClass('hide');
					// fnValue('#reason .textarea', ret.data.reason);
     //            }else{
     //        		fnValue('.submit','已通过审核');
     //        		$('.submit').addClass('no-onclick');
     //            }
                fnValue('#name',_el.userinfo.name);
                fnValue('#tel',_el.userinfo.phone);
                fnValue('#unit_id',_el.userinfo.unit_id);
                fnValue('#unit_number',_el.userinfo.unit_number);
                fnValue('#department',_el.userinfo.department);
                $('.gender').removeClass('active');
        //     }else{
        //         fnValue('#detail',template('detail-template', _el));
        //     }
        // });
    }


    
    //提交申请
    function fnSubmit(){
        var _param = {};
        _param.active_id = param.id;
        _param.sex = $('.gender.active').attr('data-sex');
        if(fnValue("#name")){
            _param.name = fnValue("#name");
        }else{
            fnToast('请填写真实姓名');
            return
        }
        if(fnValue("#tel")){
            if( fnVerify( 'Phone' ).test( fnValue( '#tel' ) )){
                _param.phone = fnValue("#tel");
            }else{
                fnToast('请填写手机号码格式错误');
                return
            }
        }else{
            fnToast('请填写手机号码');
            return
        }
        if($('.inner').val()){
            _param.unit_id = fnValue(".inner");
        }else{
            fnToast('请选择单位');
            return
        }
        if(fnValue("#department")){
            _param.department = fnValue("#department");
        }else{
            fnToast('请填写单位部门');
            return
        }
        if(fnValue("#unit_number")){
            _param.unit_number = fnValue("#unit_number");
        }else{
            fnToast('请填写工号牌');
            return
        }
			
        fnAjax({
            url: "Queandans/fnSubmitInfo",
            data: _param,
        }, function(ret){
            if( !ret.status ){
                fnOpen("wendatijiao.html",fnGetUrlParam());
            }else{
                fnToast(ret.msg);
            }
        });
    }

    
</script>
</html>
